<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>签到表单</title>
  <link rel="icon" href="/static/favicon.png" >
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.6.0/css/bootstrap.min.css" />
  <style>
    body {
      background: linear-gradient(-45deg, #EE7752, #E73C7E, #23A6D5, #23D5AB);
      background-size: 400% 400%;
      animation: gradient-animation 5s ease infinite;
    }

    @keyframes gradient-animation {
      0% {
        background-position: 0% 50%;
      }
      50% {
        background-position: 100% 50%;
      }
      100% {
        background-position: 0% 50%;
      }
    }

    h1 {
      text-align: center;
      margin-top: 50px;
      color: #fff;
      text-shadow: 2px 2px rgba(0,0,0,0.5);
    }

    form {
      max-width: 500px;
      margin: 0 auto;
      padding: 20px;
      border-radius: 5px;
      text-align: left; /* 将文本对齐方式设置为居中 */
    }

    div {
      margin-bottom: 20px;
    }

    label {
      display: inline-block;
      width: 100px;
      text-align: right;
      margin-right: 10px;
      font-size: 18px;
      font-weight: bold;
    }

    input[type="text"] {
      padding: 10px;
      border: 1px solid #ccc;
      border-radius: 5px;
      font-size: 18px;
      width: 100%; /* 将输入框宽度设置为100% */
      box-sizing: border-box; /* 让输入框宽度包含边框和填充 */
    }

    button[type="submit"] {
      background-color: #007bff;
      color: #fff;
      padding: 10px 20px;
      border: none;
      border-radius: 5px;
      cursor: pointer;
      font-size: 18px;
      transition: background-color 0.3s ease;
      width: 100%; /* 将提交按钮宽度设置为100% */
      box-sizing: border-box; /* 让提交按钮宽度包含边框和填充 */
    }

    button[type="submit"]:hover {
      background-color: #0069d9;
    }

    /* 响应式设计 */
    @media screen and (max-width: 767px) {
      /* 在屏幕宽度小于等于767px时，修改样式 */
      form {
        max-width: none; /* 取消最大宽度限制 */
      }
    }
  </style>
</head>
<body>
  <h1>签到表单</h1>

  <form id="sign-up-form" action="/sign-up" method="post">
    <div>
      <label for="name">姓名：</label>
      <input type="text" name="name" id="name" required>
    </div>
    <div>
      <label for="class">班级：</label>
      <input type="text" name="class" id="class" required>
    </div>
    <div>
      <label for="number">学号：</label>
      <input type="text" name="number" id="number" required>
    </div>
    <div>
      <button type="submit" id="submit-button">提交</button>
    </div>
  </form>

  <!-- 模态框 -->
  <div class="modal fade" id="confirm-modal" tabindex="-1" role="dialog" aria-labelledby="confirm-modal-label" aria-hidden="true">
    <div class="modal-dialog" role="document">
      <div class="modal-content">
        <div class="modal-header">
          <h5 class="modal-title" id="confirm-modal-label">确认信息</h5>
          <button type="button" class="close" data-dismiss="modal" aria-label="Close">
            <span aria-hidden="true">&times;</span>
         </button>
        </div>
        <div class="modal-body">
          <p>请确认以下信息：</p>
          <ul>
            <li><strong>姓名：</strong><span id="confirm-name"></span></li>
            <li><strong>班级：</strong><span id="confirm-class"></span></li>
            <li><strong>学号：</strong><span id="confirm-number"></span></li>
          </ul>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
          <button type="button" class="btn btn-primary" id="confirm-button">确定</button>
        </div>
      </div>
    </div>
  </div>

  <!-- 表格 -->
  <div class="container" id="attendance-table" style="display: none;">
    <h2>考勤历史记录</h2>
    <table class="table">
      <thead>
        <tr>
          <th>姓名</th>
          <th>班级</th>
          <th>学号</th>
          <th>考勤时间</th>
        </tr>
      </thead>
      <tbody>
        <!-- 这里可以填充考勤历史记录的数据 -->
      </tbody>
    </table>
  </div>

  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.6.0/js/bootstrap.min.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
  <script>
    // 提交表单处理函数
    function submitHandler(event) {
      event.preventDefault(); // 阻止表单默认提交行为
      // 获取表单数据
      const name = $('#name').val();
      const className = $('#class').val();
      const number = $('#number').val();
      // 弹出确认模态框
      $('#confirm-name').text(name);
      $('#confirm-class').text(className);
      $('#confirm-number').text(number);
      $('#confirm-modal').modal('show');
    }

    // 确认按钮点击处理函数
    function confirmHandler() {
      const name = $('#name').val();
      const className = $('#class').val();
      const number = $('#number').val();
      // 发送 HTTP 请求保存数据
      axios.post('/sign-up', {
        name: name,
        class: className,
        number: number
      })
      .then(function (response) {
  // 请求成功，隐藏表单，显示考勤历史记录表格
  $('#sign-up-form').hide();
  $('#attendance-table').show();
  // 在表格中显示考勤历史记录
  const attendanceData = response.data;
  const tableBody = $('#attendance-table tbody');
  attendanceData.forEach(function (item) {
    const row = $('<tr></tr>');
    const nameCell = $('<td></td>').text(item.name);
    const classCell = $('<td></td>').text(item.class);
    const numberCell = $('<td></td>').text(item.number);
    const timeCell = $('<td></td>').text(item.create_time);
    row.append(nameCell, classCell, numberCell, timeCell);
    tableBody.append(row);
  });
})
      .catch(function (error) {
        // 请求失败，弹出错误提示
        alert('请认真核对信息，稍后再试！');
      });
      // 隐藏确认模态框
      $('#confirm-modal').modal('hide');
    }

    // 注册表单提交事件处理函数
    $('#sign-up-form').submit(submitHandler);

    // 注册确认按钮点击事件处理函数
    $('#confirm-button').click(confirmHandler);
  </script>
</body>
</html>